function Bus(console) {
	this.console = console;
	this.buildMessageLogItem = function(channel, data) {
		return "[" + channel + "]" + map2json(data);
	};
	this.subscribers = new Array();
};

Bus.prototype.sendMessage = function(channel, data) {
	if(this.console != null) {
		this.console.log(this.buildMessageLogItem(channel, data));
	}
	if(this.subscribers[channel] != null) {
		this.console.log("Channel " + channel + ", subscribers.length = " + this.subscribers[channel].length);
		for(var i = 0; i < this.subscribers[channel].length; i++) {
			var callback = this.subscribers[channel][i];
			callback(data);
		}
	}
};

Bus.prototype.subscribe = function(channel, callback) {
	if(this.subscribers[channel] == null) {
		this.subscribers[channel] = new Array();
	}
	this.subscribers[channel].push(callback);
};

Bus.prototype.unsubscribe = function(channel, callback) {
	if(this.subscribers[channel] != null) {
		var found = false;
		for(var i = 0; i < this.subscribers[channel].length && !found; i++) {
			if(this.subscribers[channel][i] == callback) {
				this.subscribers[channel].splice(i, 1);
			}
		}
	}
};